package com.weilaiwd.content;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.weilaiwd.common.model.Channel;
import com.weilaiwd.common.handler.ConfigHandler;
import com.weilaiwd.content.web.IndexAction;

public class Content extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setBaseViewPath("/WEB-INF/jsp/");
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexAction.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("config.properties");
		// 配置C3p0数据库连接池插件
		DruidPlugin dp = new DruidPlugin(getProperty("jdbc.url"), getProperty("jdbc.username"), getProperty("jdbc.password"));
		me.add(dp);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		arp.setDevMode(true);
		arp.setShowSql(true);
		arp.addMapping("channel", Channel.class);
		
		dp.start();
		arp.start();
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("basePath"));
		me.add(new ConfigHandler());
	}

}
